package com.jwgf.smarowindingmachine_unity.ui;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.widget.GridView;
import android.widget.LinearLayout;

import com.jwgf.adapter.CommonAdapter;
import com.jwgf.adapter.ViewHolder;
import com.jwgf.objectbox.TubeRecord;
import com.jwgf.smarowindingmachine_unity.R;
import com.jwgf.smarowindingmachine_unity.logic.Report;

import java.util.ArrayList;
import java.util.List;

public class ProductionTubeMonitorView extends LinearLayout {
    private GridView gridView;
    private CommonAdapter adapter;
    private List<TubeRecord> list;

    public ProductionTubeMonitorView(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.production_management_tube_monitor, this);
        gridView = (GridView) findViewById(R.id.grid_view);
        list = new ArrayList<>();
        adapter = new CommonAdapter<TubeRecord>(context, list, R.layout.item_tube_monitor) {
            @Override
            public void convert(ViewHolder holder, TubeRecord item) {
                int tubeNumber = item.tubeNum;
                String isLeft = (tubeNumber & 0xffff) == 1 ? "L" : "R";
                StringBuilder builder = new StringBuilder();
                builder.append(isLeft).append(tubeNumber >> 16).append(":").append(item.count);
                holder.setText(R.id.text, builder.toString());
            }
        };
        gridView.setAdapter(adapter);

    }

    public void setData(List<TubeRecord> records) {
        list.clear();
        list.addAll(records);
        adapter.notifyDataSetChanged();
    }

}
